import { toPublish } from '@mqtt';
import { defineStore } from 'pinia';
import { showLoading } from '@/utils/prompt';
import { getTeamInfo, getCustomersInfo, getFleetInfo, getDeliveryInfo,getDeliveryFillList, getDeliveryFillListBybuye, getDeliveryDriverList } from '@/gql/administrator';
export const information = defineStore('administrator', {
  state: () => ({
    teamAll: uni.getStorageSync('team') ? uni.getStorageSync('team') : {},//团信息
    KeyCustom: uni.getStorageSync('KeyCustom') ? uni.getStorageSync('KeyCustom') : {},//大客户信息
    fleetAll: uni.getStorageSync('fleetAll') ? uni.getStorageSync('fleetAll') : {},//车队信息
    station: uni.getStorageSync('station') ? uni.getStorageSync('station') : {},//补液站信息
    getFillList: [],
    getChuFillList: [],
    getDriverList: []
  }),
  getters: {},
  actions: {
    // 车友团信息
    getDeliveryIn(num : string) {
      showLoading('加载中');
      const payload = {
        query: getTeamInfo,
        variables: { team_id: Number(num) },
      };
      toPublish(
        'ql/control/getTeamInfo',
        payload,
        (obj : any) => {
          const { getTeamInfo } = obj.data;
          this.teamAll = getTeamInfo
          uni.setStorageSync('team', this.teamAll)
        },
      );
    },
    // 大客户信息
    geKeyIn(num : string) {
      showLoading('加载中');
      const payload = {
        query: getCustomersInfo,
        variables: { customers_id: Number(num) },
      };
      toPublish(
        'ql/control/getCustomersInfo',
        payload,
        (obj : any) => {
          const { getCustomersInfo } = obj.data;
          this.KeyCustom = getCustomersInfo
          uni.setStorageSync('KeyCustom', getCustomersInfo)
        },
      );
    },
    //车队信息
    geFleetIn(num : string) {
      showLoading('加载中');
      const payload = {
        query: getFleetInfo,
        variables: { fleet_id: Number(num) },
      };
      toPublish(
        'ql/control/getFleetInfo',
        payload,
        (obj : any) => {
          const { getFleetInfo } = obj.data;
          this.fleetAll = getFleetInfo
          uni.setStorageSync('fleetAll', getFleetInfo)
        },
      );
    },
    //补液站信息
    rehydration(num : string) {
      showLoading('加载中');
      const payload = {
        query: getDeliveryInfo,
        variables: { delivery_id: Number(num) },
      };
      toPublish(
        'ql/control/getDeliveryInfo',
        payload,
        (obj : any) => {
          const { getDeliveryInfo } = obj.data;
          this.station = getDeliveryInfo
          uni.setStorageSync('station', getDeliveryInfo)
        },
      );
    },
    //补液员列表
    filler() {
      showLoading('加载中');
      const payload = {
        query: getDeliveryDriverList,
        variables: { delivery_id: this.station.id },
      };
      toPublish(
        'ql/control/getDeliveryDriverList',
        payload,
        (obj : any) => {
          const { getDeliveryDriverList } = obj.data;
          this.getDriverList = getDeliveryDriverList
        },
      );
    },
    //受液机列表
    Receiver() {
      showLoading('加载中');
      const payload = {
        query: getDeliveryFillListBybuye,
        variables: { delivery_id: this.station.id },
      };
      toPublish('ql/control/getDeliveryFillListBybuye', payload,
        (obj : any) => {
          const { getDeliveryFillListBybuye } = obj.data;
          this.getFillList = getDeliveryFillListBybuye
        },
      );
    },
    //补液机列表
    machine() {
      showLoading('加载中');
      const payload = {
        query: getDeliveryFillList,
        variables: { delivery_id: this.station.id },
      };
      toPublish('ql/control/getDeliveryFillList', payload,
        (obj : any) => {
          const { getDeliveryFillList } = obj.data;
          this.getChuFillList = getDeliveryFillList
        },
      );
    },
  },
});